﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EzDesk.Core.Model;
using EzDesk.Core.CoreImpl.Services;
using System.Web.Security;

namespace EzDesk.Core.CoreImpl
{
    public partial class CoreClientService : ICoreClientService
    {
        private ICoreService _coreService = new CoreService();

        public CoreClientService()
        {
            _coreService = new CoreService();
        }



        public string OutputStr(string str)
        {
            return "Stringsssss from server: " + str;
        }

        public IList<App> GetCurrentApps()
        {
            return _coreService.GetAllApps();
        }

        
        public void ChangeUserDept(Guid userId, Guid deptId)
        {
            _coreService.ChangeUserDept(userId, deptId);
        }

        public void ChangeUserReportId(Guid userId, Guid reportId)
        {
            _coreService.ChangeUserReportId(userId, reportId);
        }

        public void ChangeUserPosition(Guid userId, Guid positionId)
        {
            _coreService.ChangeUserPosition(userId, positionId);
        }

        public UserProfile CreateEmptyUserProfile(string userName)
        {
            return _coreService.CreateEmptyUserProfile(userName);
        }

        public UserProfile GetUserProfileById(Guid userId)
        {
            return _coreService.GetUserProfileById(userId);
        }

        public SimpleUser GetSimpleUserById(Guid userId)
        {
            return _coreService.GetSimpleUserById(userId);
        }

        public IList<SimpleUser> GetSimpleUserInfos(string userIdStrs)
        {
            return _coreService.GetSimpleUserInfos(userIdStrs);
        }

        public App GetAppByName(string appName)
        {
            return _coreService.GetAppByName(appName);
        }

        public IList<AppTask> GetAppTasksByAppName(string appName, Guid userId, string userAgent)
        {
            return _coreService.GetAppTasksByAppName(appName, userId, userAgent);
        }

        public IList<AppTask> GetAllAppTasks(Guid userId, string userAgent)
        {
            return _coreService.GetAllAppTasks(userId, userAgent);
        }

        // 返回登录Token字符串
        public string Login(string userName, string password)
        {
            // 验证UserName和pwd
            MembershipProvider membershipProvider = Membership.Provider;
            string token = string.Empty;
            if (membershipProvider.ValidateUser(userName, password))
            {
                Guid userId = _coreService.GetSimpleUserInfoByUserName(userName).Id;

                ClientTokenPool tokenPool = ClientTokenPool.Instance;
                token = tokenPool.RequestToken(userId);
            }
            return token;
        }




        public UserProfile GetUserProfileByUserName(string userName)
        {
            return _coreService.GetUserProfileByUserName(userName);
        }
    }
}
